//
//  CommentDetailCell.m
//  lvtu
//
//  Created by Apple on 12-6-28.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "CommentDetailCell.h"

@implementation CommentDetailCell
@synthesize delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        tripImageView = [[EGOImageView alloc] initWithFrame:
                         CGRectMake(10, 10, 50, 50)];
        //tripImageView.image = [UIImage imageNamed:@"bg_trip_default.png"];
        [tripImageView setPlaceholderImage:[UIImage imageNamed:@"bg_trip_default.png"]];
        [self addSubview:tripImageView];
        
        creattimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(230, 10, 50, 16)];
//        creattimeLabel.text = @"2012-03-12";
        creattimeLabel.backgroundColor = [UIColor clearColor]; 
        //creattimeLabel.textColor = [UIColor blackColor];
        creattimeLabel.font = [UIFont systemFontOfSize:9.0f];
        creattimeLabel.numberOfLines = 0;
        creattimeLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:creattimeLabel];
        
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, 100, 20)];
//        nameLabel.text = @"浪漫之旅";
        nameLabel.backgroundColor = [UIColor clearColor]; 
        nameLabel.font = [UIFont systemFontOfSize:10.0f];
        nameLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:nameLabel];
        
        contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 35, 160, 35)];
//        contentLabel.text = @"评论(0)";
        contentLabel.backgroundColor = [UIColor clearColor]; 
        contentLabel.font = [UIFont systemFontOfSize:12.0f];
        contentLabel.lineBreakMode = UILineBreakModeCharacterWrap;
        [self addSubview:contentLabel];
        
        UIButton* commentbutton = [UIButton buttonWithType:UIButtonTypeCustom];
        commentbutton.frame = CGRectMake(230, 30, 38, 38);
        [commentbutton setBackgroundImage:[UIImage imageNamed:@"btn_reply_normal.png"] forState:UIControlStateNormal];
        [commentbutton setBackgroundImage:[UIImage imageNamed:@"btn_reply_press.png"] forState:UIControlStateHighlighted];
        [commentbutton addTarget:self action:@selector(commentButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:commentbutton];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
//    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)commentButtonPressed:(id)sender
{
    [delegate touchUpCommentDetailCellButton:m_index];
}

- (void)updateCommentDetail:(NSDictionary*)info Index:(NSInteger)index
{
    m_index = index;
    NSString* coverurl = [info objectForKey:@"c_member_icon"];
    NSString* time = [info objectForKey:@"create_time"];
    NSString* name = [info objectForKey:@"name"];
    NSString* content = [info objectForKey:@"content"];
    if (coverurl && ![coverurl isEqualToString:@""]) {
        [tripImageView setImageURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.wxlvtu.com/img.php?filename=%@",coverurl]]];
    }
    else {
        [tripImageView setImage:[UIImage imageNamed:@"bg_trip_default.png"]];
    }
    if ([time isEqualToString:@"0"]) {
        creattimeLabel.text = @"";
    }
    else
    {
        creattimeLabel.text = time;
    }
    nameLabel.text = name;
    contentLabel.text  = content;
    int tempHeight = [content sizeWithFont:[UIFont systemFontOfSize:12.0f]
                                      constrainedToSize:CGSizeMake(160, 9999) lineBreakMode:UILineBreakModeCharacterWrap].height;
    [contentLabel setFrame:CGRectMake(70, 35, 160, tempHeight+5)];
}

@end
